import { createStore } from 'vuex'

export default createStore({
  state: {
    // 当前用户
    usernow:'',
    // 当前页面所在的项目ID ---- 用于关联初始项目
    ItemID:'',
    // 项目列表、需求列表=>登录时自动获取至此然后依据他们来做出显示,
    // 项目列表 ---- 已根据用户登录进行筛选
    ItemList:'',
    // 需求列表 ---- 已根据用户登录进行筛选 ---- 关于用户的全部需求都在这里了(包含含用户项目的项目小组成员)
    DemandList:[],
    // 当前所在页面真实的项目
    real_Item:'',
    // 当前所在页面真实的全部需求
    real_Demand:[],
    // 当前项目组织负责人真实负责人 ---- 不一定是当前登录人
    main_person:''
  },
  mutations: {
    UpdateState(state,value){
      state.usernow = value[0]
      state.ItemID = value[3]
      state.DemandList = value[2]
      state.ItemList = value[1]
      state.ItemList.some((element) => {
        if (element.Item_ID === state.ItemID) {
          state.real_Item = element;
          state.main_person = element.main_person;
        }
      });
      if(value[4] != undefined){
        state.real_Demand = []
      }
      state.DemandList.some((e) => {
        if (e.Item_ID == state.ItemID) {
          state.real_Demand.push(e);
        }
      });
      console.log(state.real_Demand)
    },
    useSessionStorage(state,value){
        state.ItemID = value[0]
        state.DemandList =  value[1]
        state.ItemList =  value[2]
        state.main_person =  value[3]
        state.real_Item =  value[4]
        state.usernow =  value[5]
        state.real_Demand =  value[6]
        console.log(state.usernow)
    },
    clearState(state){
      state.usernow = "";
      state.ItemList = "";
      state.DemandList = [];
      state.ItemID = "";
      state.real_Item = "";
      state.main_person = "";
      state.real_Demand = [];
    },
    jumpItem(state,value){
      state.ItemID = value;
      state.ItemList.some((element) => {
        if (element.Item_ID === state.ItemID) {
          state.real_Item = element;
          state.main_person = element.main_person;
        }
      });
      state.DemandList = []
      state.DemandList.some((e) => {
        if (e.Item_ID == state.ItemID) {
          state.real_Demand.push(e);
        }
      });
    },
    addRealDemand(state,value){
      state.real_Demand.push(value);
    },
    addRealItemMember(state,value){
      state.real_Item.member.push(value)
    }
  },
  actions: {
  },
  modules: {
  }
})
